// packageA/pages/package/nav_add_apply/nav_register/nav_supplier/supplier.js
const mybehavior = require("../../../behaviors/requests")
Page({

  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    base_urlstr: "https://logisticsengineering.gree.com/container_manage_api/user_manage",
    phone_num: "",
    employee_num: "",
    name: "",
    department: "",
    ver_code: "",
  },
  getGeneralData(e) {
    console.log(e.detail);
    let key = Object.keys(e.detail)
    let key_data = e.detail[key]
    console.log(key);
    console.log(key_data);
    this.setData({
      [key]: key_data
    })

  },
  freshUserData() {
    this.setData({
      phone_num: wx.getStorageSync('phone_num'),
      employee_num: wx.getStorageSync('_id'),
      name: wx.getStorageSync('name'),
      department: wx.getStorageSync('department'),

    })
  },
  submit() {
    let data = {
      phone_num: this.data.phone_num,
      employee_num: this.data.employee_num,
      ver_code: this.data.ver_code,
    }
    console.log(data);
    let url = this.data.base_urlstr + "/register_general_user"

    this.post(url, data).then(res => {

      if (res.code == 20000) {
        wx.showToast({
          title: res.msg,
          icon: 'success'
        })
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
      }
    }).catch(err => {
      console.log(err);
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })

  },
  reset() {
    let childObj = this.selectComponent('.my-component')
    childObj.setData({
      phone_num: "",
      ver_code: "",

    })
    this.setData({
      phone_num: "",
      employee_num: "",
      name: "",
      department: "",
      ver_code: "",

    })


  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.freshUserData()

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})